<template>
	<view class="loginContainer">
		<!-- <image src="../../static/images/loginIcon.png" class="loginIcon"></image> -->
		<button class="loginBtnBox flex" @click="smallLogin()">
			<image src="../../static/images/wxIcon.png" class="wxIcon"></image>
			<view>授权登录</view>
		</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// mobilePhone: '',//手机号码
				openId: '',
				unionId: '',
				// userName: '',
			}
		},
		onLoad(options) {
			console.log(options)
			if(options.openId && options.openId != undefined) {
				this.openId = options.openId;
				this.smallLogin();
				/* this.userName = options.userName;
				this.mobilePhone = options.mobilePhone; */
			}else {
				uni.showToast({
					title: '用户信息不正确',
					icon: 'none',
					success: () => {
						setTimeout(()=> {
							uni.reLaunch({
								url: '/pages/home/home'
							});
						},1000)
					}
				})
			}
		},
		methods: {
			// openId: oco3q6mXXXiW8ZcAHH0ssHSsW1Ro   unionId: owqif0TPgY_48mQ-8MJbEf-MdS0M
			smallLogin(){
				let _this = this;
				uni.request({
					// 请求路径
					url: getApp().globalData.serverUrl+'/auth/auth/api/wxLoginByOpenId?route=auth',
					// 请求参数code
					data: {
						channelId: getApp().globalData.channelId,
						appId: getApp().globalData.appid,
						// mobilePhone: _this.mobilePhone,
						openId: _this.openId,
						// userName: _this.userName
					},
					method: 'GET',
					success(res){
						console.log(res)
						alert("登录成功！");
						getApp().globalData.token = res.data.data.token;
						uni.setStorage({
							key: 'token',
							data: res.data.data.token
						});
						uni.reLaunch({
							url: '/pages/index/index'
						});
					}
				});
			}
		}
	}
</script>

<style>
	.loginContainer {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		overflow: hidden;
	}
	.txtOverFlow {
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	.flex {
		display: flex;
	}
	.loginIcon {
		width: 369rpx;
		height: 369rpx;
		display: block;
		margin: 0 auto;
		margin-top: 31rpx;
	}
	.selectSchoolBox {
		width: 88%;
		height: 98rpx;
		line-height: 98rpx;
		margin: 80rpx 45rpx 45rpx 45rpx;
		background: #F6F6F6;
		border-radius: 49rpx;
	}
	.inputBox {
		margin-left: 46rpx;
	}
	.moreIcon3 {
		width: 66rpx;
		height: 16rpx;
		position: absolute;
		right: 20px;
		top: 43%;
	}
	.loginBtnBox {
		width: 88%;
		height: 98rpx;
		line-height: 98rpx;
		margin: 80rpx 45rpx 45rpx 45rpx;
		background: linear-gradient(90deg, #19AD78, #1EBE85);
		border-radius: 49rpx;
		text-align: center;
		font-size: 32rpx;
		color: #FFFFFF;
	}
	.wxIcon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 13rpx;
		margin-top: 36rpx;
		margin-left: 34%;
	}
	.sendMessageBtn {
		width: 100px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		color: #FFFFFF;
		font-size: 26rpx;
		background: linear-gradient(90deg, #19AD78, #1EBE85);
	}
	.inputBox2 {
		width: 85%;
		height: 30px;
		line-height: 30px;
		border: 1px solid #efefef;
		border-radius: 10px;
		margin: 0 auto;
		padding: 10px 0 10px 10px;
		margin-bottom: 10px;
	}
	.inputVal {
		margin-top: 4px;
		width: 500px;
	}
	.imgCodeUrl {
		width: 242px;
		height: 30px;
		margin-right: 14px;
	}
</style>
